// Copyright (C) 2013 Michael Leviston (michael.leviston@gmail.com)

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef ECS_COMPONENTBASE_H
#define ECS_COMPONENTBASE_H

#include "Component.h"

namespace ECS
{
	/// \brief Base class for common functionality of all components.
	///
	/// The component base handles all the common component functions, such as setting and getting the unique ID and type;
	///
	/// \author Michael Leviston
	template <class T>
	class ComponentBase : public Component 
	{
	public:

		/// Constructor
		ComponentBase()	
			: id(0), bMarkedForRemoval(false)
		{}

		/// Get Unique ID of component
		unsigned int GetID() { return id; }

		/// Set Unique ID of component
		void SetID(unsigned int i) { id = i; }

		/// Get Type of component 
		unsigned int GetType()  { return T::type; }

		/// Mark Component for removal from world
		void MarkForRemoval()  { bMarkedForRemoval = true; }

		/// Get the Unique ID of the entity which owns this component
		unsigned int GetParentEntityID() { return parentEntityID; }

		/// Set the Unique ID of the entity which owns this component
		void SetParentEntityID(unsigned int ID) { parentEntityID = ID; } 

		
		static unsigned int type;	///< Unique Type of component (Generated via CRTP)

	private:
		unsigned int parentEntityID;		///< Unique ID of parent Entity
		unsigned int id;					///< Unique ID of this component
		bool bMarkedForRemoval; ///< Is the component marked for removal
	};

	static unsigned int nextCType = 0;
	template <typename T> unsigned int ComponentBase<T>::type(nextCType++);

}

#endif // ECS_COMPONENTBASE_H